<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box {
            display: block;
            width: 300px;
            height: 100px;
            margin: 100px auto;
            background-color: lightblue;
        }
        .box span {
            font-size: 40px;
            line-height: 100px;
            color: yellow;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="box">
        <span>☆</span>
        <span>☆</span>
        <span>☆</span>
        <span>☆</span>
        <span>☆</span>
    </div>
    
    <script src="js/jquery-1.12.4.min.js"></script>
    <script>
        // 获取元素
        var $spans = $("span")
        // 添加事件
        $spans.each(function (i) {
            $(this).mouseenter(function () { 
                // 获取当前事件源的下标值
                var idx = $spans.index()
                // 下标小于事件源的全部变成 ★
                for(var n = i ; n >= 0; n--)           
                $spans.eq(n).text("★")

            })
            // 鼠标离开，全部恢复默认  
            $(this).mouseleave(function () {
                $spans.text("☆")
            })   
        })
    </script>
</body>
</html>